<div class="row">
    <div class="col-lg-12">
        <?php if(validation_errors()): ?>
            <div class="alert alert-error" style="margin: 10px 10px 10px 0px;">
              <button data-dismiss="alert" class="close" type="button">×</button>
              <?php echo validation_errors(); ?>
            </div>
        <?php endif;?>
        <?php if(@$data == 201):?>
            <div class="alert alert-error" style="margin: 10px 10px 10px 0px;">
              <button data-dismiss="alert" class="close" type="button">×</button>
              <span>Kênh đã tồn tại. Thêm thất bại!</span>
            </div>
        <?php endif;?>
        <h1 class="page-header">Sửa thông tin chương trình</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel-body">
            <div class="row">
                <?php echo form_open()?>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label>Tên chương trình</label>
                            <input id="tvshow" name="tvshow" class="form-control" placeholder="Nhập tên chương trình" value="<?php echo $data? $data['name'] : ''?>"/>
                        </div>
                        <div class="form-group">
                            <label>Kênh phát sóng</label>
                            <?php echo $fview->selectType($selectChannel, $data? $data['channel_id'] : '', 'channel', 'Chọn kênh phát sóng');?>
                        </div>
                        <div class="form-group">
                            <label>Giờ phát sóng</label>
                            <input autocomplete="off" id="datetimepicker" type="text" class="form-control" value="<?php $date = new DateTime(); $date->setTimestamp($data['schedule']); echo $date->format('H:i Y/m/d')?>" name="time_start" placeholder="Thời gian bắt đầu" />
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Lưu</button>
                        </div>
                    </div>
                    <!-- /.col-lg-6 (nested) -->
                    <div class="col-lg-6">
                        <div class="form-group bg-show">
                            <label>Chọn background</label>
                            <div style="position: relative">
                                <input class="image-input" type="file" name="img_uploads" id="background" onchange="convertimage('background', 'background_tvshow_', 'show_background_');" value="" />
                                <label class="hidden-label" for="background"></label>
                                <img src="<?php echo $data ? $imgurl.$data['background'] : ''?>" id="show_background_" class="aligncenter" style="vertical-align: middle;width: 320px;height: 568px;border: 1px solid #CCC;background: #CCC" onerror="this.src='<?php echo $baseurl;?>public/images/no-image.png';"/>
                                <input type="hidden" name="background_tvshow_" id="background_tvshow_" value="" />
                                <input type="hidden" name="background_tvshow_verify" id="background_tvshow_verify" value="<?php echo $data ? $data['background'] : ''?>" />
                                <input type="hidden" name="background_tvshow_check" id="background_tvshow_check" value="<?php echo $data ? $data['background'] : ''?>" />
                            </div>
                        </div>
                    </div>
                    <!-- /.col-lg-6 (nested) -->
                </form>
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.col-lg-12 -->
</div>

<link rel="stylesheet" type="text/css" href="<?php echo $baseurl.'public/theme'?>/datetimepicker/jquery.datetimepicker.css"/>
<script src="<?php echo $baseurl.'public/theme'?>/datetimepicker/jquery.datetimepicker.js"></script>
<script>

$('#datetimepicker').datetimepicker({value:'',lang:'vi',format:'H:i Y/m/d',formatDate:'Y-m-d',step:5});

function convertimage(id, id_parse, img_show)
{
    var id = id;
    var id_parse = id_parse;
    var img_show = img_show;
    var filesSelected = document.getElementById(id).files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) 
        {
            $("#"+id_parse).attr('value', fileLoadedEvent.target.result);
            $("#"+id_parse+"check").val('1');
            $("#"+img_show).attr('src', fileLoadedEvent.target.result);
        };

        fileReader.readAsDataURL(fileToLoad);
    }
}

</script>